<template>
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectErpPs.title"
             :visible.sync="dialog_selectErpPs.visible"
             width="1100px">

    <!-- 检索条件 -->
    <el-form :model="dialog_selectErpPs.queryParams"
             :inline="true" v-show="dialog_selectErpPs.showSearch" label-width="68px">

      <!-- 结束时间 -->
      <el-form-item label="结束时间" prop="dtFinish">
        <el-input
          v-model="dialog_selectErpPs.queryParams.dtFinish"
          placeholder="请输入结束时间"
          clearable
          size="small"
          @keyup.enter.native="getList_erpPs"
        />
      </el-form-item>

      <!-- 开始时间 -->
      <el-form-item label="开始时间" prop="dtStart">
        <el-input
          v-model="dialog_selectErpPs.queryParams.dtStart"
          placeholder="请输入开始时间"
          clearable
          size="small"
          @keyup.enter.native="getList_erpPs"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
                   @click="getList_erpPs">搜索</el-button>
      </el-form-item>

    </el-form>


    <!-- 列表 -->
    <el-table v-loading="loading" :data="dialog_selectErpPs.erpPsList" row-key="erpPsUuid" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>

      <el-table-column type="expand" >
        <template slot-scope="props">
          <el-form label-position="left" class="demo-table-expand">
            <el-form-item label="备注：">
              <span>{{ props.row.docNote }}</span>
            </el-form-item>
            <el-form-item label="审核人：">
              <span>{{ props.row.confirmUserName }}</span>
            </el-form-item>
            <el-form-item label="审核结果：">
              <dict-tag :options="dict.type.oa_dict_confirm_status" :value="props.row.oaDictConfirmStatus"/>
            </el-form-item>
            <el-form-item label="审核时间：">
              <span>{{ props.row.confirmDt }}</span>
            </el-form-item>
            <el-form-item label="审核意见：">
              <span>{{ props.row.confirmNote }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="计划时间" align="center" prop="docDt" width="150"/>
      <el-table-column label="计划订单号" align="center" prop="docNum" width="150"/>
      <el-table-column label="物料名称" align="center" prop="itemName" width="150"/>
      <el-table-column label="物料编码" align="center" prop="itemNum" width="160"/>
      <el-table-column label="数量" align="center" prop="psQty"/>
      <el-table-column label="计量单位" align="center" prop="wmsDictMeasuringUnit" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_dict_measuring_unit" :value="scope.row.wmsDictMeasuringUnit"/>
        </template>
      </el-table-column>
      <el-table-column label="产品名称" align="center" prop="orderItemName" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="产品编码" align="center" prop="orderItemNum" width="150"/>

      <el-table-column label="数量" align="center" prop="orderDetailQty"/>
      <el-table-column label="计量单位" align="center" prop="orderUnit" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_dict_measuring_unit" :value="scope.row.orderUnit"/>
        </template>
      </el-table-column>
      <el-table-column label="制单人" align="center" prop="attentionUserName"/>

      <el-table-column label="工艺规程" align="center" prop="processDocNum" width="150"/>

      <el-table-column label="销售号" align="center" prop="orderDocNum" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="show_order(scope.row)"
          >{{scope.row.orderDocNum}}<i class="el-icon-caret-right"></i>
          </el-button>
        </template>
      </el-table-column>

      <el-table-column label="开始日期" align="center" prop="dtStart" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dtStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束日期" align="center" prop="dtEnd" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dtEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>


      <el-table-column label="审核状态" align="center" prop="oaDictConfirmStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.oa_dict_confirm_status" :value="scope.row.oaDictConfirmStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="已完成" align="center" prop="sysYesNoDone" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoDone"/>
        </template>
      </el-table-column>
      <el-table-column label="请选择" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button type="success" plain
                     size="small"
                     icon="el-icon-check"
                     @click="selectErpPs_done(scope.row)"
          ><span> 选择</span></el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="dialog_selectErpPs.total>0"
      :total="dialog_selectErpPs.total"
      :page.sync="dialog_selectErpPs.queryParams.pageNum"
      :limit.sync="dialog_selectErpPs.queryParams.pageSize"
      @pagination="getList_erpPs"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog_hide_selectErpPs">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {listPs} from "@/api/erp/ps";
  export default{
    dicts: ['sys_normal_disable','wms_dict_measuring_unit','sys_yes_no','oa_dict_confirm_status'],
    props: {
      // 角色编号
      roleId: {
        type: [Number, String]
      }
    },
    data() {
      return {
        dialog_selectErpPs: {
          visible: false,
          showSearch: true,
          title: "请选择生产计划",
          total: 0,
          erpPsList: [],
          queryParams:{
            pageNum: 1,
            pageSize: 10,
            itemName: null,
            oaDictConfirmStatus: null,
          }
        },

        // 遮罩层
        loading: true,

        // 遮罩层
        visible: false,
        // 选中数组值
        erpPsUuids: [],
        // 总条数
        total: 0,
        // 生产计划数据
        erpPsList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          roleId: undefined,
          userName: undefined,
          phonenumber: undefined
        },
      };
    },
    methods: {


      /** 读取列表：车间计划 */
      getList_erpPs() {
        this.loading = true;
        this.dialog_selectErpPs.queryParams.oaDictConfirmStatus = 'pass'
        listPs(this.dialog_selectErpPs.queryParams).then(response => {
          console.log( response )
          this.dialog_selectErpPs.erpPsList = response.rows;
          this.dialog_selectErpPs.total = response.total;
          this.loading = false;
        });
      },



      // 完成：选择物料
      selectErpPs_done(user) {
        this.dialog_selectErpPs.visible = false;
        this.$emit("ok", user );
      },


      // 对话框：显示 - 选择物料
      dialog_show_selectErpPs() {
        this.getList_erpPs()
        this.dialog_selectErpPs.visible = true;
        this.dialog_selectErpPs.title = "选择生产计划";
      },

      // 对话框：隐藏 - 选择物料
      dialog_hide_selectErpPs() {
        this.dialog_selectErpPs.visible = false;
      },

      clickRow(row) {
        this.$refs.table.toggleRowSelection(row);
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.erpPsUuids = selection.map(item => item.erpPsUuid);
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList_erpPs();
      },


      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
